<?php

use Fisharebest\Webtrees\Auth;
use Fisharebest\Webtrees\I18N;

?>

<?php if ($articles->isEmpty()) : ?>
    <?= I18N::translate('No news articles have been submitted.') ?>
<?php endif ?>

<?php foreach ($articles as $n => $article) : ?>
    <?php if ($n === 5 && count($articles) > 5) : ?>
        <p>
            <button class="btn btn-sm btn-secondary" data-toggle="collapse" data-target="#more-news-<?= e($block_id) ?>" role="button" aria-expanded="false" aria-controls="more-news-<?= e($block_id) ?>">
                <?= view('icons/add') ?>
                <?= I18N::translate('show more') ?>
            </button>
        </p>
        <div class="collapse" id="more-news-<?= e($block_id) ?>">
    <?php endif ?>

    <div class="news_box">
        <div class="news_title" dir="auto"><?= $article->subject ?></div>
        <div class="news_date"><?= view('components/datetime', ['timestamp' => $article->updated]) ?></div>
        <div dir="auto"><?= $article->body ?></div>

        <?php if (Auth::isManager($tree)) : ?>
            <hr>
            <form method="post" action="<?= e(route('module', ['module' => 'user_blog', 'action' => 'DeleteJournal', 'news_id' => $article->news_id, 'tree' => $tree->name()])) ?>">
                <?= csrf_field() ?>
                <a class="btn btn-link" href="<?= e(route('module', ['module' => 'user_blog', 'action' => 'EditJournal', 'news_id' => $article->news_id, 'tree' => $tree->name()])) ?>">
                    <?= I18N::translate('Edit') ?>
                </a>
                |
                <button class="btn btn-link" type="submit" data-confirm="<?= I18N::translate('Are you sure you want to delete “%s”?', e($article->subject)) ?>" onclick="return confirm(this.dataset.confirm);">
                    <?= I18N::translate('Delete') ?>
                </button>
            </form>
        <?php endif ?>
    </div>
<?php endforeach ?>

<?php if (count($articles) > 5) : ?>
    </div>
<?php endif ?>

<p>
    <a class="btn btn-link" href="<?= e(route('module', ['module' => 'user_blog', 'action' => 'EditJournal', 'tree' => $tree->name()])) ?>">
        <?= I18N::translate('Add a journal entry') ?>
    </a>
</p>
